﻿using System;
using System.Collections.Generic;
using System.IO;

namespace DeleteWords
{
    class DeleteWords
    {
        static List<string> ReadList()
        {
            StreamReader readList = new StreamReader("..\\..\\WordsList.txt");
            string word = readList.ReadLine();
            List<string> words = new List<string>();

            using (readList)
            {
                while (word != null)
                {
                    words.Add(word);
                    word = readList.ReadLine();
                }
            }
            return words;
        }

        static void Main()
        {
            try
            {
                using (StreamReader reader = new StreamReader("..\\..\\File.txt"))
                {
                    string line;
                    List<string> words = ReadList();

                    using (StreamWriter writer = new StreamWriter("..\\..\\Tmp.txt"))
                    {
                        while ((line = reader.ReadLine()) != null)
                        {
                            for (int i = 0; i < words.Count; i++)
                            {
                                line = line.Replace(words[i], "");
                            }
                            writer.WriteLine(line);
                        }
                    }
                }

                File.Delete("..\\..\\File.txt");
                File.Move("..\\..\\Tmp.txt", "..\\..\\File.txt");
            }
            catch (FileNotFoundException fnfe)
            {
                Console.Error.WriteLine(fnfe.Message);
            }
            catch (DirectoryNotFoundException dnfe)
            {
                Console.Error.WriteLine(dnfe.Message);
            }
            catch (ArgumentNullException ane)
            {
                Console.Error.WriteLine(ane.Message);
            }
            catch (ArgumentException ae)
            {
                Console.Error.WriteLine(ae.Message);
            }
            catch (OutOfMemoryException ofme)
            {
                Console.Error.WriteLine(ofme.Message);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
            }
        }
    }
}
